package beautiful.butterfly.drds.data_exchange.read_and_write_data;


import beautiful.butterfly.drds.data_exchange.data_exchange.exchanger.Produce;
import beautiful.butterfly.drds.data_exchange.util.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.SQLException;
import java.util.List;

public class Reader extends AbstractReader
{


    public static class Job extends AbstractJob
    {
        private static final Logger log = LoggerFactory
                .getLogger(Job.class);

        private Configuration originalConfig = null;
        private beautiful.butterfly.drds.data_exchange.read_and_write_data.reader.Reader.Job job;


        public void init() throws SQLException
        {
            this.originalConfig = super.getJobConfiguration();


            this.job = new beautiful.butterfly.drds.data_exchange.read_and_write_data.reader.Reader.Job();
            this.job.init(this.originalConfig);
        }

        @Override
        public void preCheck() throws SQLException
        {
            init();
            this.job.preCheck(this.originalConfig);

        }

        @Override
        public List<Configuration> split(int adviceNumber) throws SQLException
        {
            return this.job.split(this.originalConfig, adviceNumber);
        }

        @Override
        public void post()
        {
            this.job.post(this.originalConfig);
        }


        public void destroy()
        {
            this.job.destroy(this.originalConfig);
        }

    }

    public static class Task extends AbstractTask
    {

        private Configuration readerSliceConfig;
        private beautiful.butterfly.drds.data_exchange.read_and_write_data.reader.Reader.Task readerTask;


        public void init()
        {
            this.readerSliceConfig = super.getJobConfiguration();
            this.readerTask = new beautiful.butterfly.drds.data_exchange.read_and_write_data.reader.Reader.Task(super.getTaskGroupId(), super.getTaskId());
            this.readerTask.init(this.readerSliceConfig);

        }


        public void startRead(Produce produce) throws SQLException
        {


            this.readerTask.startRead(this.readerSliceConfig, produce,
                    this.getAbstractTaskPluginCollector());
        }


        public void post()
        {
            this.readerTask.post(this.readerSliceConfig);
        }


        public void destroy()
        {
            this.readerTask.destroy(this.readerSliceConfig);
        }

    }

}
